package minidb.parse.exps;

import minidb.querycondition.IOperand;

public class OperandInt extends Operand implements IOperand
{
	public Integer intValue;

	public OperandInt(Integer val)
	{
		this.intValue = val;
	}

	@Override
	public Boolean Equals(IOperand o)
	{
		if (OperandNull.class.isInstance(o))
			return false;
		if(OperandDouble.class.isInstance(o))
			return this.intValue.doubleValue()==((OperandDouble)o).doubleValue;
		return this.intValue.intValue() == ((OperandInt) o).intValue;
	}

	@Override
	public Boolean NotEq(IOperand o)
	{
		if (OperandNull.class.isInstance(o))
			return false;
		else
			return !(this.Equals(o));
	}

	@Override
	public Boolean LittleThan(IOperand o)
	{
		if (OperandNull.class.isInstance(o))
			return false;
		if(OperandDouble.class.isInstance(o))
			return this.intValue.doubleValue()<((OperandDouble)o).doubleValue;
		return this.intValue.intValue() < ((OperandInt) o).intValue;
	}

	@Override
	public Boolean GreateEq(IOperand o)
	{
		if (OperandNull.class.isInstance(o))
			return false;
		return !(this.LittleThan(o));
	}

	@Override
	public Boolean GreateThan(IOperand o)
	{
		if (OperandNull.class.isInstance(o))
			return false;
		if(OperandDouble.class.isInstance(o))
			return this.intValue.doubleValue()>((OperandDouble)o).doubleValue;
		return this.intValue.intValue() > ((OperandInt) o).intValue;
	}

	@Override
	public Boolean LittleEq(IOperand o)
	{
		if (OperandNull.class.isInstance(o))
			return false;
		return !(this.GreateThan(o));
	}

	@Override
	public Boolean IsNull()
	{
		return false;
	}

	@Override
	public Boolean IsNotNull()
	{
		return true;
	}

	@Override
	public Boolean LIKE(IOperand o)
	{
		return false;
	}

	@Override
	public Boolean NOTLIKE(IOperand o)
	{
		return false;
	}

	// ===============================================================================
	@Override
	public String Print()
	{
		return String.format("%s", this.intValue);
	}
	
	@Override
	public String Print_Base()
	{
		return this.Print();
	}

	@Override
	public Operand DupOperand()
	{
		return new OperandInt(this.intValue);
	}

	@Override
	public Object ToValue()
	{
		return this.intValue;
	}

}
